package net.jsoft.pms.config.mybatis;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
@MapperScan(basePackages = "net.jsoft.pms.mapper", sqlSessionFactoryRef = "oracleSessionFactory")
public class MybatisSCSConfig
{

    @Bean(name = "oracleSessionFactory")
    @Autowired
    @Primary
    public SqlSessionFactory sqlSessionFactory(@Qualifier("oracleDS") DataSource datasource) throws Exception
    {
        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(datasource);
        return sessionFactory.getObject();
    }
}
